<?php
declare(strict_types = 1);

namespace IMOcean\Tests;

use IMOcean\Server\Coroutine\Swoole;
use IMOcean\Closure\Closure;
use IMOcean\Closure\ClosureList;

/**
 * Class Swoole
 * @package IMOcean\Servers
 */
class Test
{
    public static function handle()
    {
        var_dump(__METHOD__);
    }

    public static function redis()
    {
        Swoole::execute(new Closure(function () {
            $redis = new \Redis();

            $redis->connect('127.0.0.1', 6379);
            $redis->auth('ziyuyu');

            var_dump($redis->ping());
        }));
    }


    public static function curl()
    {
        Swoole::execute(new Closure(function () {
            $curl = curl_init();

            curl_setopt($curl, CURLOPT_URL, 'https://www.baidu.com');
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

            $result = curl_exec($curl);

            curl_close($curl);

            var_dump($result);
        }));
    }

    public static function mysql_pdo()
    {
        Swoole::execute(new Closure(function () {
            $pdo = new \PDO('mysql:host=127.0.0.1:3306;dbname=sosoul;charset=utf8', 'ziyuyu', 'ziyuyu');

            $statement = $pdo->prepare('select * from `user` where `phone` = 17369284185');

            $statement->execute();

            var_dump($statement->fetchAll());
        }));
    }

    public static function mysqli()
    {
        Swoole::execute(new Closure(function () {
            $id = 9;
            $mysqli = new \mysqli('127.0.0.1', 'ziyuyu', 'ziyuyu', 'sosoul', 3306);
            $statement = $mysqli->prepare('select `id` from `user` where `phone` = 17369284185');
            $statement->bind_result($id);
            $statement->execute();
            $statement->fetch();
            var_dump($id);
        }));
    }
}
